﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NetLogExtend.Log4Net
{
    public class Log4Provider : ILoggerProvider
    {

        private readonly CustomConsoleLoggerConfiguration _config;
        private readonly ConcurrentDictionary<string, CustomConsoleLogger> _loggersDictionary 
            = new ConcurrentDictionary<string, CustomConsoleLogger>();

        public Log4Provider(CustomConsoleLoggerConfiguration config)
        {
            _config = config;
        }

        public ILogger CreateLogger(string categoryName)
        {
            return _loggersDictionary.GetOrAdd(categoryName, name => new CustomConsoleLogger(name, _config));
        }

        public void Dispose()
        {
            _loggersDictionary.Clear();
        }
    }
}
